import { AxiosResponse } from "axios";
import type { ReturnImageInfosObj } from "@/types";
import {
  fetchImgInfosListInvisible,
  resurgenceSinglePictureById,
} from "./resurrection";
import request from "./request";
import { getTotalPicsNumber, getPagePicsInfos } from "./pages";
import { getWaterfallPicInfosList } from "./water";

/**
 * @deprecated
 */
export const fetchImgUrlsList = (): Promise<
  AxiosResponse<{ picture_infos: string[] }>
> => {
  return request({
    url: "/all_visual",
    method: "get",
  });
};

export const fetchImgInfosList = (): Promise<
  AxiosResponse<ReturnImageInfosObj>
> => {
  return request({
    url: "/all_visual_info",
    method: "get",
  });
};

export const fetchNotR18ImgInfosList = (): Promise<
  AxiosResponse<ReturnImageInfosObj>
> => {
  return request({
    url: "/get_r12_pics",
    method: "get",
  });
};

export const getOrderImageListByStar = (): Promise<
  AxiosResponse<ReturnImageInfosObj>
> => {
  return request({
    url: "/all_chosen",
    method: "get",
  });
};

export const deactivateImageByID = (id: number) => {
  return request({
    url: "/deactivate",
    method: "get",
    params: { id },
  });
};

export const getPraiseNumberByIDApi = (
  id: number
): Promise<AxiosResponse<number>> => {
  return request({
    url: "/praise_number",
    method: "get",
    params: { id },
  });
};

export const praiseImageByID = (id: number): Promise<AxiosResponse<number>> => {
  return request({
    url: "/praise",
    method: "get",
    params: { id },
  });
};

export const getOrderImageListByCreateTime = (): Promise<
  AxiosResponse<ReturnImageInfosObj>
> => {
  return request({
    url: "/visual_order",
    method: "get",
    params: {
      condition: "create_time",
      rev: -1,
    },
  });
};

export const getOrderImageListByCreateTimeReverse = (): Promise<
  AxiosResponse<ReturnImageInfosObj>
> => {
  return request({
    url: "/visual_order",
    method: "get",
    params: {
      condition: "create_time",
      rev: 1,
    },
  });
};

export const getOrderImageListByPraiseNumber = (): Promise<
  AxiosResponse<ReturnImageInfosObj>
> => {
  return request({
    url: "/visual_order",
    method: "get",
    params: {
      condition: "praise",
      rev: -1,
    },
  });
};

export const getOrderImageListByPraiseNumberReverse = (): Promise<
  AxiosResponse<ReturnImageInfosObj>
> => {
  return request({
    url: "/visual_order",
    method: "get",
    params: {
      condition: "praise",
      rev: 1,
    },
  });
};

export const getOrderImageListByID = (): Promise<
  AxiosResponse<ReturnImageInfosObj>
> => {
  return request({
    url: "/visual_order",
    method: "get",
    params: {
      condition: "id",
      rev: 1,
    },
  });
};

export const getOrderImageListByIDReverse = (): Promise<
  AxiosResponse<ReturnImageInfosObj>
> => {
  return request({
    url: "/visual_order",
    method: "get",
    params: {
      condition: "id",
      rev: -1,
    },
  });
};

export const choosePicByID = (id: number): Promise<AxiosResponse<string>> => {
  return request({
    url: "/choose_pic",
    method: "get",
    params: { id },
  });
};

export const r12PicByID = (id: number): Promise<AxiosResponse<string>> => {
    return request({
        url: "/update_pic_to_r12",
        method: "get",
        params: { id },
    });
}

export const getMainPicPath = (id: number): Promise<AxiosResponse<string>> => {
  return request({
    url: "/get_true_path",
    method: "get",
    params: { id },
  });
};

export const getCarouselImagesList = (
  num?: string
): Promise<AxiosResponse<ReturnImageInfosObj>> => {
  return request({
    url: "/get_carousel",
    method: "get",
  });
};

export const getCandidate = (
    keyword:string, num?: number
): Promise<AxiosResponse<{"tag_candidate":{"tag_name":string, "count": number}[]}>> => {
  return request({
    url: "/search_tag_candidate",
    method: "get",
    params: {
      keyword,
      num: num || 10,
    },
  });
};


export const searchFromTags = (
  keyword: string
): Promise<AxiosResponse<{"picture_infos":{"id":number,"url":string, "praise":number}[]}>> => {
  return request({
    url: "/search_tag",
    method: "get",
    params: {
      keyword,
    },
  });
};

export const getHotTag = (): Promise<AxiosResponse<{"hot_tag":{"tag_name":string, "count":number}[]}>> => {
    return request({
        url: "/get_hot_tag",
        method: "get",
    });
}

export const getRandomTag = (
    num?: number
): Promise<AxiosResponse<{"tags":{"tag_name":string}[]}>> => {
    return request({
        url: "/get_random_tag",
        method: "get",
        params: {
            num: num || 5,
        }
    });
}

export {
  fetchImgInfosListInvisible,
  getTotalPicsNumber,
  getPagePicsInfos,
  getWaterfallPicInfosList,
  resurgenceSinglePictureById,
};
